<template>
  <!-- 新鲜好物 -->
  <div class="home-new" ref="target">
    <XtxPanel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
      <!-- 传入右侧插槽 -->
      <template #right>
        <XtxMore />
      </template>
      <transition name="fade">
        <!-- 传入默认插槽 -->
        <ul  class="goods-list" v-if="goodsList.length">
          <li v-for="item in goodsList" :key="item.id">
            <RouterLink to="/">
              <img :src="item.picture" alt="">
              <p class="name ellipsis">{{item.name}}</p>
              <p class="price">&yen;{{item.price}}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton bg="#f0f9f4" v-else />
      </transition>
    </XtxPanel>
  </div>
</template>

<script setup>
import { findNew } from '@/api/home'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hooks'

const { target, result: goodsList } = useLazyData(findNew)
</script>

<style lang="scss" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    @include hoverShadow;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: $priceColor;
    }
  }
}
.fade{
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity .5s .2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}
</style>
